package test.gateway.a.controllers;

import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import test.gateway.a.dtos.DateResponse;

import java.util.Date;

/**
 * 测试使用 feign 传参，date 类型会不正确问题
 */
@RestController
public class ParamDateController {

    @GetMapping("/reciveDate")
    public DateResponse reciveDate(@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date begin, @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")  Date end){
        System.out.println(DateFormatUtils.ISO_DATETIME_FORMAT.format(begin));
        System.out.println(DateFormatUtils.ISO_DATETIME_FORMAT.format(end));

        Date date = DateUtils.addHours(begin, 5);
        return new DateResponse(date);
    }
}
